home *** CD-ROM | disk | FTP | other *** search
- //
- // E++ Tutorial Lernabschnitt: 1 Beispiel: 2 hello2
- //
- //
- // Hello world with ET++:
- // - the string "hello world" is shown in a scrollable window
- // - the current layout can be loaded from a file
- //
-
- #ifdef ET_DUMP
- #include "ET_Dump.h"
- #endif
-
- #include "ET++.h"
- #include "Collection.h"
-
- //---- HelloView -------------------------------------------------------------------
-
- class HelloView: public View {
- TextItem *viewtext;
- public:
- MetaDef(HelloView);
- HelloView(Document *dp, Rectangle itsExtent) : View(dp, itsExtent)
- { }
- void Draw(Rectangle r);
- void SetText(TextItem *t);
- };
-
- MetaImpl(HelloView, (TP(viewtext)));
-
- void HelloView::SetText(TextItem *t)
- {
- viewtext = t;
- // force the the text item to calculate its extent
- viewtext->CalcExtent();
- // install the text item in this view
- viewtext->SetContainer(this);
- ForceRedraw();
- }
-
- void HelloView::Draw(Rectangle r)
- {
- viewtext->DrawAll(r);
- }
-
-
-
- //---- HelloDocument ---------------------------------------------------------------
-
- class HelloDocument : public Document {
- HelloView *view;
- TextItem *text;
- public:
- MetaDef(HelloDocument);
- HelloDocument();
- ~HelloDocument();
- Window *DoMakeWindows();
- void DoRead(istream &, class FileType *);
- void DoWrite(ostream &, int);
- };
-
- MetaImpl(HelloDocument, (TP(view), TP(text)));
-
- HelloDocument::HelloDocument() : Document("HELLO")
- {
- static int family= 1;
-
- family= (family+1) % 10; // cycle through first 10 font families
- text= new TextItem("hello world ",
- new_Font(GrFont(family), 24, GrFace(eFaceBold|eFaceShadow)));
- text->SetOrigin(Point(50));
- }
-
- HelloDocument::~HelloDocument()
- {
- SafeDelete(view);
- SafeDelete(text);
- }
-
- Window *HelloDocument::DoMakeWindows()
- {
- view= new HelloView(this, Point(400));
- view->SetText(text);
- return new Window(this, Point(250), eWinDefault, new Scroller(view));
- }
-
- void HelloDocument::DoRead(istream &is, class FileType *ft)
- {
- Document::DoRead(is, ft); // read file type information
- SafeDelete(text);
- is >> text;
- view->SetText(text);
- }
-
- void HelloDocument::DoWrite(ostream &os, int flag)
- {
- Document::DoWrite(os, flag); // store file type information
- os << text;
- }
-
- //---- HelloApplication -------------------------------------------------------------------
-
- class HelloApplication: public Application {
- public:
- MetaDef(HelloApplication);
- HelloApplication(int argc, char **argv) : Application(argc, argv, "HELLO")
- { ApplInit(); }
- Document *DoMakeDocuments(Symbol)
- { return new HelloDocument; }
- };
-
- MetaImpl0(HelloApplication);
-
- //---- main --------------------------------------------------------------------
-
- main(int argc, char **argv)
- {
- return HelloApplication(argc, argv).Run();
- }
-